package cloud.xiguapi.ubas.analysis.pv.model;

import cloud.xiguapi.ubas.model.PageViewCount;
import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

/**
 * @author 大大大西西瓜皮🍉
 * date: 2021-5-19 上午 09:02
 * desc:
 */
public class FilePVCountResult implements WindowFunction<Long, PageViewCount, Integer, TimeWindow> {

    @Override
    public void apply(Integer key, TimeWindow window, Iterable<Long> input, Collector<PageViewCount> out) throws Exception {
        out.collect(PageViewCount.builder()
                .url(key.toString())
                .windowEnd(window.getEnd())
                .count(input.iterator().next())
                .build());
    }
}